#ifndef __TCPSERVER_H__
#define __TCPSERVER_H__

#include "Epoll.h"
#include "Acceptor.h"
#include "TcpConnection.h"
#include <string>
#include <unordered_map>

using std::string;
using std::unordered_map;

class TcpServer
{
public:
    TcpServer(string ip, int port);
    
    void start();

    void setConnectionCb(TcpConnectionCb cb);
    void SetMessageCb(TcpConnectionCb cb);
    void setCloseCb(TcpConnectionCb cb);

	void AcceptorCb();
    void OnConnectionCb(shared_ptr<TcpConnection> &pconn);
	void OnMessageCb(shared_ptr<TcpConnection> &pconn);
	void OnCloseCb(shared_ptr<TcpConnection> &pconn);

private:
    Epoll epoll_;
    Acceptor acceptor_;

	unordered_map<int, shared_ptr<TcpConnection>> map_;
};

#endif
